import { app, ipcMain, globalShortcut, BrowserWindow } from "electron";
import * as remote from "@electron/remote/main";
import { winparams } from "./params";
import { WINDOW_PORT, RENDER_HTML_PATH, logger } from "@/settings";
import {
  setWindowById,
  getMainWindow,
} from "@/jc-electron-tools/windows";
import { createTrayIcon } from '@/utils/tray'

// import devtools from '@vue/devtools'

function newWinAdmin() {
  const window = new BrowserWindow(winparams as any);
  const id = setWindowById(window);
  remote.enable(window.webContents);

  // 用于渲染进程获取 admin window 的 id
  ipcMain.on('get-admin-window', (event) => {
    event.reply('admin-window', id);
  });
  logger.gradient(`WINDOW_PORT = ${JSON.stringify(WINDOW_PORT)}`);
  logger.gradient(`WINDOW_PORT.admin = ${WINDOW_PORT.admin}`);
  if (process.env.NODE_ENV === "development") {
    logger.debug(
      `[New Window] Start Admin Window At URL: http://localhost:${WINDOW_PORT.admin}/`
    );
    window.loadURL(` http://127.0.0.1:${WINDOW_PORT.admin}/`);
  } else {
    window.loadFile(`${RENDER_HTML_PATH.admin}`);
  }
  window.webContents.openDevTools();
  // 托盘图标
  createTrayIcon();
  return id;
}






export { newWinAdmin };
